package cn.zlj.nmcc.mq;

import cn.zlj.nmcc.domain.MediaFile;
import com.alibaba.fastjson.JSON;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.print.attribute.standard.Media;

@Component
public class MediaProducer {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    public boolean sendMsg(MediaFile mediaFile){
        //先将mediaFile转化为字符串
        String mediaFileJsonStr = JSON.toJSONString(mediaFile);
        //同步消息
        SendResult sendResult = rocketMQTemplate.syncSend("media-push-topic:media-push-tag", mediaFileJsonStr);
        //发送消息
        SendStatus sendStatus = sendResult.getSendStatus();
        //是否发送消息成功
        return sendStatus.equals(SendStatus.SEND_OK)?true:false;
    }


}
